package com.allenyuan.gui;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JLabel;
import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.SwingConstants;
import javax.swing.UnsupportedLookAndFeelException;

import java.awt.CardLayout;

public class MainFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6942480336848679670L;

	private JPanel contentPane;
	
	private JPanel panel;
	

	public static void main(String[] args) {
		
		try {
			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainFrame frame = new MainFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setTitle("雕刻机测试");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 522, 460);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		GridBagLayout gbl_contentPane = new GridBagLayout();
		gbl_contentPane.columnWidths = new int[]{150, 0, 0, 20, 0};
		gbl_contentPane.rowHeights = new int[]{25, 0, 15, 0};
		gbl_contentPane.columnWeights = new double[]{0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
		contentPane.setLayout(gbl_contentPane);
		
		JLabel sideImg = new JLabel();
		sideImg.setHorizontalAlignment(SwingConstants.CENTER);
		sideImg.setBackground(Color.RED);
		sideImg.setIcon(null);
		
		GridBagConstraints gbc_sideImg = new GridBagConstraints();
		gbc_sideImg.gridheight = 3;
		gbc_sideImg.insets = new Insets(0, 0, 0, 5);
		gbc_sideImg.gridx = 0;
		gbc_sideImg.gridy = 0;
		contentPane.add(sideImg, gbc_sideImg);
		
		panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.insets = new Insets(0, 0, 5, 5);
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 2;
		gbc_panel.gridy = 1;
		contentPane.add(panel, gbc_panel);
		
		panel.setLayout(new CardLayout(0, 0));
		GuiContext context = new GuiContext();
		panel.add(new ConnectionTestPanel(context), ConnectionTestPanel.class.getName());
		panel.add(new ModeSelectPanel(context), ModeSelectPanel.class.getName());
		panel.add(new GCodeImportPanel(context), GCodeImportPanel.class.getName());
		panel.add(new BitmapImportPanel(context), BitmapImportPanel.class.getName());
		panel.add(new PrintProgressPanel(context), PrintProgressPanel.class.getName());
	}
	
}
